package com.allen.common

import android.content.Context
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModelProvider
import com.alibaba.android.arouter.launcher.ARouter
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity

/**
 *  @Autor  lwl
 *  日期    2021/3/11
 *  目的
 */
abstract class BaseAct<T : ViewDataBinding, M : BaseVM> : RxAppCompatActivity() {
    var savedInstanceState: Bundle? = null
    lateinit var mContext: Context
    lateinit var mbinding: T
    lateinit var mVm: M
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        ARouter.getInstance().inject(this)
        mContext = this
        this.savedInstanceState = savedInstanceState
        mVm =
            ViewModelProvider(this).get(getBaseViewModelClass());
        mbinding = DataBindingUtil.setContentView(this, getResId())
        mbinding.lifecycleOwner = this
        bindingVM()
        initData()
        initView()
        initObserve()
        initEvent()
    }


    abstract fun getResId(): Int
    abstract fun initData()
    abstract fun initView()
    abstract fun initEvent()
    abstract fun initObserve()
    abstract fun bindingVM()  // 需要绑定
    abstract fun getBaseViewModelClass(): Class<M>
}
